package com.rescueworkers.utils;

import java.io.File;
import java.io.RandomAccessFile;

public class FileUtils {
	public static void WriteTxtFile(String strcontent, String strFilePath) {
		// 每次写入时，都换行写
		String strContent = strcontent + "\n";
		try {
			File file = new File(strFilePath);
			if (!file.exists()) {
				file.createNewFile();
			} else {
				file.delete();
				file.createNewFile();
			}
			RandomAccessFile raf = new RandomAccessFile(file, "rw");
			raf.seek(file.length());
			raf.write(strContent.getBytes());
			raf.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void WriteTxtFileNoDelete(String strcontent, String strFilePath,String fileName) {
		// 每次写入时，都换行写
		String strContent = strcontent + "\n";
		try {
			File file = new File(strFilePath);
			try {
				if(!file.exists()){
					file.mkdirs();
				}
			} catch (Exception e) {
			}
			File files = new File(strFilePath+"/"+fileName);
			if (!files.exists()) {
				files.createNewFile();
			} else {
//				files.delete();
//				files.createNewFile();
			}
			RandomAccessFile raf = new RandomAccessFile(files, "rw");
			raf.seek(files.length());
			raf.write(strContent.getBytes());
			raf.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
